Device: Device Information

更新时间:
2024-06-11
下载文档

Device: Device Information

The device module provides multiple interfaces for applications to obtain information about smart devices that have been scanned and found to have access to EdgerOS.

Developers can determine whether these interfaces work in the EdgerOS mobile App environment through the following code:

edger.env().then(data => {
  if (data.env === 'edgerapp') {
    // We work in EdgerOS mobile App environment.
  }
}).catch(error => {
  console.error(error);
});

Functions

edger.device.showDiscoverPanel()

Show the device discovery panel.

The parameters of the showDiscoverPanel method include:

  • config {Object}

    • height {number} Panel height, which is the percentage of the full screen.
  • filter {Array} Device id list.

    • devid: The filtered device id.
  • Returns: {Promise} Fulfill upon success with an empty object.

Example

const config = {
  height: 0.9
}
edger.device.showDiscoverPanel(config).catch(error => {
  console.error(error);
});

async / await

async function showDevicePanel() {
  try {
    const config = {
      height: 0.9
    }
    edger.device.showDiscoverPanel(config);
  } catch (error) {
    console.error(error);
  }
}

edger.device.hideDiscoverPanel()

Hide the device discovery panel.

  • Returns: {Promise} Fulfill upon success with an empty object.

Example

edger.device.hideDiscoverPanel().catch(error => {
  console.error(error);
});

async / await

async function hideDiscoverPanel() {
  try { 
    await edger.device.hideDiscoverPanel();
  } catch (error) {
    console.error(error);
  }
}

Events

The unified event listener provided by Web-SDK:

const listener = (payload) => {
  // Event handling...
}

// add listener
edger.device.addEventListener('some-event', listener);

// or 
// onAction() is an alias of addEventListener().
edger.device.onAction('some-event', listener);

// remove listener
edger.device.removeEventListener('some-event', listener);

// remove all listeners
edger.device.removeAllListeners();

add

This event will be notified when devices have been added.

  • Returns: {Array} A chosen device list.

Get an object of result, the object includes:

  • join {Boolean} Join status.
  • alias {String} Device alias name.
  • report {Object} Detail information about the device.
    • name {String} Device name.
    • type {String} Device type.
    • excl {Boolean} Exclusive status.
    • desc {String} Description.
    • model {Number} Model number.
    • vendor {String} Vendor name.
  • security {Boolean} Whether the device is secure.
  • addr {String} Ip address.
  • devid {String} Device id.

Example

const listener =  (payload) => {
  payload.forEach((item) => {
    const { join, alias, report, security, addr, devid } = item;
    console.log("device add result:", join, alias, report, security, addr, devid);
  })
}

edger.device.addEventListener('add', listener);
文档内容是否对您有所帮助?
有帮助
没帮助